package com.example.yuejian21.nongfusanquan.yuejian21.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.ClubAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.CouchAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.fragment.ClubFragment;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Clubbean;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Couchbean;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Clubmodel;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Couchmodel;
import com.squareup.picasso.Picasso;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Nongfusanquan on 2017-10-17.
 */

public class CouchActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private Button couch_return;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_couch);
        recyclerView=(RecyclerView)findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));//设置布局
        initViews();
        initEvent();
        getData();

    }

    private void initViews() {
        couch_return = (Button) findViewById(R.id.return_couch);
    }

    private void initEvent() {
        couch_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              finish();

            }
        });
    }

    private void getData() {

        Couchmodel Model = new Couchmodel();
        Call<List<Couchbean>> call = Model.getcouchlist();
        call.enqueue(new Callback<List<Couchbean>>() {
            @Override
            public void onResponse(Call<List<Couchbean>> call, Response<List<Couchbean>> response) {
                List<Couchbean> data = response.body();  //获取数据
                recyclerView.setAdapter(new CouchAdapter(CouchActivity.this, data));
            }

            @Override
            public void onFailure(Call<List<Couchbean>> call, Throwable t) {

            }
        });

    }
}
